<?php

	header("Content-Type: text/html;charset=utf-8");

	include("../function/_nosql.php"); //
	include("../function/function.php");

	include("../_include.user.judge.php");

	$kboy_user = $_SESSION['kboy_user'];

	$kboy_userid = $_SESSION['kboy_userid'];

	$aid = chkstr(trim($_REQUEST['aid']));
	
	$kboy_shangche = chkstr(trim($_REQUEST['shangche']));
	if(empty($aid)){

		echo erro("参数错误");

	}

	if(!is_numeric($aid)){

		echo erro("参数错误");

	}

	if(getNewsNums("kboy_forum_active","id=$aid") <1){

		echo erro("参数错误");

	}
    
    if($kboy_shangche){
		$active_center = $kboy_shangche;
	}else{
		$active_center = getClassName("kboy_forum_active", "active_center","id = $aid");
	}
	$order_no = build_order_no();
	//$order_no = time();

	$user_sql = "select * from kboy_user where uid=$kboy_userid limit 1";

	$user_rows = mysql_query($user_sql);

	while($user_rs = mysql_fetch_array($user_rows)){

		$user_realname = $user_rs['user_realname'];
		
		$user_phone = $user_rs['user_phone'];

		$user_tel = $user_rs['user_tel'];
		
		$user_sex = $user_rs['user_sex'];
		$user_idcard = $user_rs['user_idcard'];
		if(empty($user_realname) || empty($user_idcard) || empty($user_phone) && empty($user_tel))
		{
			echo ok('请完善您的基本资料', 'user_basics.php');
		}

	}
	if(!empty($user_phone)){
		$order_phone=$user_phone;
	}else{
		$order_phone=$user_tel;
	}
	$sex = substr($user_idcard,-2,1);
		if($sex%2==0){
			$sex = 0;
		}else{
			$sex = 1;
		}
	$mysql = new sqlstr("kboy_order"); 

	$news_sql = $mysql -> deleteSql("uid=$kboy_userid and aid=$aid");

	mysql_query($news_sql);

	$mysql -> set("uid",$kboy_userid,true);
	$mysql -> set("order_phone",$order_phone);
	$mysql -> set("order_no",$order_no);
	$mysql -> set("order_realname",$user_realname);
	$mysql -> set("order_sex",$sex);
	$mysql -> set("order_shangche",$active_center);
	$mysql -> set("order_idcard",$user_idcard);
	//性别
//	$mysql -> set("order_shangche",$order_shangche);
	
	$mysql -> set("aid",$aid,true);

	$mysql -> set("order_num",1);
	
	$news_sql = $mysql -> insertSql();

	$news_res = mysql_query($news_sql);

	if($news_res){
		echo ok("报名成功！","../user_order.php");
	}else{
		echo erro("报名失败，请联系18514024178");
	}

?>